package edu.neusoft.yuejian_09.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import java.util.List;

import edu.neusoft.yuejian_09.R;
import edu.neusoft.yuejian_09.bean.Show;
import it.sephiroth.android.library.picasso.Picasso;

import static edu.neusoft.yuejian_09.base.Constant.POST_PHOTO_URL;

/**
 * Created by Administrator on 2017/10/13.
 */

public class MyPostListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContex;
    private List mDataList;
    private ViewHolder viewHolder;
    private LayoutInflater mLayoutInflater;

    public MyPostListAdapter(Context mContext, List mDataList) {
        this.mContex =  mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).
                inflate(R.layout.cardview_my_post, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Show entity = (Show) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.post_info.setText(entity.getS_content());
        viewHolder.post_time.setText(entity.getS_date());
     //Log.d("s","post_time");
        String p_pic = POST_PHOTO_URL+entity.getS_pic();
        //System.out.print("pic");
        if (!p_pic.equals("")) {
            Picasso.with(mContex).load(p_pic).into(viewHolder.post_pic);
        }

//        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Bundle bundle=new Bundle();
//                bundle.putInt("t_id",entity.getT_id());
//                bundle.putString("t_name",entity.getT_name());
//                bundle.putInt("t_price",entity.getT_price());
//                bundle.putString("t_address",entity.getT_address());
//                bundle.putString("t_time",entity.getT_time());
//                bundle.putString("t_picture",entity.getT_picture());
//                bundle.putString("t_phone",entity.getT_phone());
//                Intent intent=new Intent(mContex, TrainDetailActivity.class);
//                intent.putExtras(bundle);
//                mContex.startActivity(intent);
//            }
//        });
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView post_pic;
        TextView post_time,post_info;

        public ViewHolder(View itemView) {
            super(itemView);
            post_time = (TextView) itemView.findViewById(R.id.post_time);
            post_info = (TextView) itemView.findViewById(R.id.post_info);
            post_pic = (ImageView) itemView.findViewById(R.id.pic);
        }
    }
}